<template>

<div id="UserInfo">
  <el-row>
    <mu-appbar title="玩家信息" style="background-color:#409EFF">
      <mu-icon-button  icon="arrow_back_ios" slot="left" :to="{name: 'Home' }"/>
    </mu-appbar>
  </el-row>
  <el-row>
    <el-col :span="12">
    </el-col>
    <el-col :span="12">
      <i class="el-icon-arrow-down" style="float:right" @click="handleTools"></i>
    </el-col>
  </el-row>

  <div class= "tools" v-show="tools">
    <el-row>
      <el-col :xs="6" :sm="4" :md="3" :lg="3">
        玩家账号
      </el-col>
      <el-col :xs="18" :sm="20" :md="21" :lg="21">
        <el-input v-model="condition.uid" size="mini" @blur="getUserInfo"></el-input>
      </el-col>
    </el-row>
    <el-row v-if="this.isGm">
      <el-col :xs="6" :sm="4" :md="3" :lg="3">
        账号类型
      </el-col>
      <el-col :xs="18" :sm="20" :md="21" :lg="21">
        <el-select v-model="condition.validity" placeholder="请选择" @change="init">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-col>
    </el-row>
  </div>

  <el-row>
    <el-table
      :data="tableData"
      style="width: 100%"
      size="mini">
      <!-- <el-table-column v-if="this.isGm">
        <template slot-scope="scope">
          <el-button v-if="scope.row.validity" type="danger" icon="el-icon-check" size="mini" @click='showDialog(scope.row.uid)'>冻结</el-button>
          <el-button v-if="!scope.row.validity" type="primary" icon="el-icon-check" size="mini" @click='showUnfrozenDialog(scope.row.uid)'>解封</el-button>
        </template>
      </el-table-column> -->
      <el-table-column
        prop="uid"
        label="玩家ID">
      </el-table-column>
      <el-table-column
        prop="binderUid"
        label="上级ID">
      </el-table-column>
      <!-- <el-table-column
        prop="organizer"
        label="顶级ID">
      </el-table-column> -->
      <el-table-column
        prop="nickName"
        label="昵称">
      </el-table-column>
      <el-table-column
        prop="todayTime"
        label="今日游戏时长">
      </el-table-column>
      <el-table-column
        prop="totalTime"
        label="总计游戏时长">
      </el-table-column>
      <el-table-column
        prop="offLineTime"
        label="未登录游戏时长">
      </el-table-column>
    </el-table>
  </el-row>

  <el-row>
    <center>
      <el-pagination
        small
        layout="prev, pager, next"
        :total="condition.total"
        :page-size="condition.pageSize"
        :current-page="condition.currentPage"
        @current-change="handleCurrentChange">
      </el-pagination>
    </center>
  </el-row>

  <el-dialog title="冻结账号" :visible.sync="dialogFormVisible">
    <el-row>
      <el-col :span="6">
        <span>冻结原因</span>
      </el-col>
      <el-col :span="18">
        <el-input v-model="lockingReason" placeholder="请输入内容"></el-input>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="6">
        <span>是否永结冻结</span>
      </el-col>
      <el-col :span="18">
        <el-radio v-model="isUnlock" label="0">永久</el-radio>
        <el-radio v-model="isUnlock" label="1">暂时</el-radio>
      </el-col>
    </el-row>
    <el-row v-if = "this.isUnlock === '1'">
      <el-col :span="6">
        <span>解封时间</span>
      </el-col>
      <el-col :span="18">
        <el-date-picker
          v-model="unlockingTime"
          type="datetime"
          placeholder="选择日期"
          value-format="yyyy-MM-dd HH:mm:ss"
          style="width:90%">
        </el-date-picker>
      </el-col>
    </el-row>

    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="frozen">确 定</el-button>
    </div>
  </el-dialog>

  <mu-dialog :open="unFrozenDialog" title="提示" @close="close">
    确认解封？
    <mu-flat-button slot="actions" @click="close" primary label="取消"/>
    <mu-flat-button slot="actions" primary @click="unFrozen" label="确定"/>
  </mu-dialog>

</div>

</template>

<style>
#UserInfo  .el-row {
  margin-bottom: 16px;
}
#UserInfo  .el-col {
  margin-bottom: 8px;
}
#UserInfo .el-dialog {
  width: 80%;
}
#UserInfo .el-picker-panel .el-date-picker .el-popper .has-time {
  left: 20px
}
</style>

<script>
  export default {
    data () {
      return {
        tools: true,
        newAgent: 0,
        totalAgent: 0,
        tableData: [

        ],
        condition: {
          startDay: this.$time.getDateBefore(new Date(), 0),
          endDay: this.$time.getDateBefore(new Date(), 0),
          uid: '',
          currentPage: -1,
          pageSize: 10,
          total: 0,
          account: sessionStorage.getItem('account'),
          validity: -1
        },
        isGm: false,
        dialogFormVisible: false,
        isUnlock: "0",
        unlockingTime: this.$time.getDateBefore(new Date(), 30),
        lockingReason: '',
        uid: 0,
        unFrozenDialog: false,
        options: [{
          value: -1,
          label: '全部'
        }, {
          value: 0,
          label: '已冻结'
        }, {
          value: 1,
          label: '未冻结'
        }]
      }
    },
    methods: {
      handleTools () {
        if (this.tools) {
          this.tools = false
        } else {
          this.tools = true
        }
      },
      getUserInfo () {
        let that = this
        if (this.condition.uid === '' || this.condition.uid.length === 0) {
          this.condition.uid = -1
        }
        this.$axios({
          method: 'get',
          url: '/api/CarrieroperatorService.getUserInfo',
          params: this.condition
        })
        .then(function (resp) {
          that.initCondition()
          if (resp.data.status === 'success') {
            that.tableData = resp.data.data
            that.condition.total = resp.data.page.total
          }
        })
      },
      init () {
        this.getUserInfo()
      },

      initCondition () {
        this.condition.uid = ''
      },
      handleCurrentChange (val) {
        this.condition.currentPage = val
        this.getUserInfo()
      },
      showDialog (uid) {
        this.uid = uid
        this.dialogFormVisible = true
      },
      frozen () {
        this.$axios({
          method: 'post',
          url: '/api/AuthService.frozenUser',
          params: {isUnlock: this.isUnlock, unlockingTime: this.unlockingTime, lockingReason: this.lockingReason, uid: this.uid}
        })
        .then(resp => {
          if (resp.data.status === 'success') {
            this.$message.success('冻结成功')
            this.init()
            this.dialogFormVisible = false
          } else {
            this.$message.error(resp.data.cause)
          }
        })
      },
      unFrozen () {
        this.$axios({
          method: 'post',
          url: '/api/AuthService.unFrozenUser',
          params: {uid: this.uid}
        })
        .then(resp => {
          if (resp.data.status === 'success') {
            this.$message.success('解封成功')
            this.unFrozenDialog = false
            this.init()
          } else {
            this.$message.error(resp.data.cause)
          }
        })
      },
      showUnfrozenDialog (uid) {
        this.uid = uid
        this.unFrozenDialog = true
      },
      close () {
        this.unFrozenDialog = false
      }
    },
    mounted () {
      if (sessionStorage.getItem('role') === 'gm') {
        this.isGm = true
      }
      this.init()
    }
  }
</script>
